// showPickerView

import 'package:flutter/cupertino.dart';

Future<dynamic> showPickerView({
  int? initialIndex,
  required BuildContext context,
  required List<String> items,
  required Function(int) onSelected,
}) {
  return showCupertinoModalPopup(
    context: context,
    builder: (context) {
      var index = initialIndex ?? 0;
      var controller = FixedExtentScrollController(initialItem: index);
      return Container(
        height: 250,
        color: CupertinoColors.white,
        child: Column(
          children: [
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                CupertinoButton(
                  child: const Text('Cancel'),
                  onPressed: () => Navigator.of(context).pop(),
                ),
                CupertinoButton(
                  child: const Text('Confirm'),
                  onPressed: (){
                    onSelected(index);
                    Navigator.of(context).pop();},
                ),
              ],
            ),
            Expanded(
              child: CupertinoPicker(
                scrollController: controller,
                itemExtent: items.length.toDouble(),
                onSelectedItemChanged: (idx) => index = idx,
                children: items.map((e) => Center(child: Text(e))).toList(),
              ),
            )
          ],
        )
      );
    },
  );
}